# encoding: utf-8
import sys
from time import sleep
from multiprocessing import Pool
import io

import json
import threading
from multiprocessing import Queue
from selenium import webdriver
from selenium.common.exceptions import ElementClickInterceptedException, NoSuchElementException
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
sys.setrecursionlimit(1000000)
chrome_options = webdriver.ChromeOptions()
# 设置浏览器初始 位置x,y & 宽高x,y
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_argument(f'--window-position={217},{92}')
chrome_options.add_argument(f'--window-size={1222},{816}')
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
# chrome_options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
chrome_options.add_argument('–headless')
desired_capabilities = DesiredCapabilities.CHROME  # 修改页面加载策略
desired_capabilities["pageLoadStrategy"] = "none"
driver = webdriver.Chrome(options=chrome_options)
# with open('stealth.min.js') as f:
#     js = f.read()
# driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
#   "source": js
# })
driver.set_page_load_timeout(10)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": """Object.defineProperty(navigator, 'webdriver', {get: () => undefined})""",
})
wait = WebDriverWait(driver, 20)


def login(n, m):
    try:
        iframe = driver.find_element_by_tag_name('iframe')
        driver.switch_to.frame(iframe)
    except:
        pass
    try:
        name = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#fm-login-id')))
        price = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#fm-login-password')))
        prices = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '.fm-btn')))
    finally:
        pass
    name.send_keys(n)
    price.send_keys(m)
    prices.click()

def dianji():
    pass






if __name__ == '__main__':
    driver.get('https://www.zhipin.com/web/boss/index')
    # login()


# 无信息数据--补充数据
